<template>
    <div class="vue-box sbot sbot-fluid">
        <!-- 参数栏 -->
        <div class="c-panel">
            <el-form :inline="true">
                <!-- 表单 -->
                <sa-item v-model="m.selectMenus" type="cascaderPanel" name="上级菜单" :options="dataTree"
                    :props="{ multiple: true, value: 'id', label: 'name', checkStrictly: true }"
                    :show-all-levels="false" />
                <sa-item v-model="m.name" type="text" name="菜单名" br />
                <sa-item v-model="m.icon" type="text" name="菜单图标" br />
                <sa-item v-model="m.code" type="text" name="识别码" placeholder="唯一标识" br />
                <sa-item v-model="m.path" type="text" name="访问地址" br />
                <sa-item v-model="m.component" type="text" name="组件" placeholder="父级默认（Layout）" br />

                <sa-item v-model="m.affix" type="enum" name="固定位置" jtype="3" :jv="dims.YES_OR_NO" br />
                <sa-item v-model="m.hidden" type="enum" name="隐藏标识" jtype="3" :jv="dims.YES_OR_NO" br />
                <sa-item v-model="m.isAuth" type="enum" name="权限标识" jtype="3" :jv="dims.YES_OR_NO" br
                    title="子菜单只有一个时，是否显示根菜单" />
                <sa-item v-model="m.level" type="enum" name="菜单等级" jtype="3" :jv="dims.MENU_LEVEL" br />
                <sa-item v-model="m.alwaysShow" type="enum" name="显示菜单" jtype="3" :jv="dims.YES_OR_NO" br />

                <sa-item v-model="m.commonFlag" type="enum" name="通用标识" jtype="3" :jv="dims.YES_OR_NO" br />
                <sa-item v-model="m.status" type="enum" name="启用状态" jtype="3" :jv="dims.YES_OR_NO" br />
                <sa-item v-model="m.note" type="text" name="描述" br />
                <sa-item v-model="m.sort" type="num" name="序号" br />
                <sa-item name="" br class="s-ok">
                    <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
                </sa-item>
            </el-form>
        </div>
    </div>
</template>

<script>

export default {
    name: 'dict-update',
    props: { param: Object },
    data() {
        return {
            // 超级对象
            m: this.createModel(),
            // 缓存字典
            dims: this.param.dims,
            dataTree: []
        }
    },
    created: function () {
        this.getCurMenus(),
        this.getInfo()
    },
    methods: {
        createModel() {
            return {
                id: this.param.id
            }
        },
        // 变更
        ok: function () {
            // 表单校验
            let m = this.m;
            if (!m.id) {
                sa.checkNull(m.name, '请输入菜单名');
            }
            sa.checkNull(m.status, '请确认是否启用');
            sa.checkNull(m.path, '请确认跳转地址');
            sa.checkNull(m.component, '请输入组件名');

            // 添加
            sa.ajax('/menu/update', m, function (res) {
                if (res.code == 200) {
                    sa.alert(res.msg, function () {
                        this.m = this.createModel();
                        sa.closeModel();
                        sa.currView().f5();
                    }.bind(this));
                }
            }.bind(this), { type: 'post' });
        },
        // 获取详情
        getInfo() {
            sa.ajax('/menu/getById', { id: this.param.id }, function (res) {
                this.m = res.data;
            }.bind(this), { type: "get" });
        },
        // 查询服务及菜单
        getCurMenus() {
            sa.ajax('/current/menus', { id: sa.$sys.getCurSid() }, function (res) {
                this.dataTree = res.data.bt
            }.bind(this), { type: 'get' })
        },
    }
}
</script>

<style scoped></style>